<?php

require_once dirname(__FILE__) . '/../lib/patient_question_answer_commentGeneratorConfiguration.class.php';
require_once dirname(__FILE__) . '/../lib/patient_question_answer_commentGeneratorHelper.class.php';

/**
 * patient_question_answer_comment actions.
 *
 * @package    docplus.co.za
 * @subpackage patient_question_answer_comment
 * @author     Fox Matuku
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class patient_question_answer_commentActions extends autoPatient_question_answer_commentActions
{

    public function executeRespond(sfWebRequest $request)
    {
        $this->patientQuestionAnswer = PatientQuestionAnswerTable::getInstance()->find($request->getParameter("answer_id", null));
        $patientQuestionAnswerComment = new PatientQuestionAnswerComment();

        if (!is_object($this->patientQuestionAnswer))
        {
            die("No answer id passed");
        }

        $patientQuestionAnswerComment->setPatientQuestionAnswer($this->patientQuestionAnswer);

        if ($this->getUser()->isAuthenticated())
        {
            $patientQuestionAnswerComment->setUserId($this->getUser()->getDpUser()->getId());
        }
        $this->form = new PatientQuestionAnswerCommentForm($patientQuestionAnswerComment);

        if ($request->isMethod('post'))
        {
            $this->form->bind($request->getParameter($this->form->getName()));
            if ($this->form->isValid())
            {
                try
                {
                    $patientQuestionAnswerComment = $this->form->save();

                    // send the asker the doctors response
                    $this->getUser()->setFlash('notice', 'Thanks for successfully submitting your comment.');

                    echo $patientQuestionAnswerComment->getId();
                    exit;
                }
                catch (Exception $e)
                {
                    throw $e;
                    // invoke the event here so we get the error via email
                }
            }
        }
    }

    public function executeResponse(sfWebRequest $request)
    {
        $this->patientQuestionAnswerComment = PatientQuestionAnswerCommentTable::getInstance()->find($request->getParameter("comment_id", null));
    }

}
